
#ifndef __TCONSTRAINTS_H_
#define __TCONSTRAINTS_H_

#include <vector>

using std::vector;

template<class T>
class TConstraints {
   
public:
   
   TConstraints() {
   }
   
   TConstraints(int n) {
      positions.resize(n);
      ids.resize(n);
   }
   
   ~TConstraints() {
   }
   
   const TConstraints& operator=(const TConstraints &cs) {
      clear();
      positions.resize(cs.size());
      ids.resize(cs.size());
      positions = cs.positions;
      ids = cs.ids;
      return *this;
   }
   
   /// Inserts a new constraint at the end
   void push_back(const T &c) {
      positions.push_back(c);
      ids.push_back(-1);
   }
   void push_back(const T &c, int id) {
      positions.push_back(c);
      ids.push_back(id);
   }
   
   /// Clear the constraints
   void clear() { ids.clear(); positions.clear(); }
   /// Returns true if constraints list is empty
   bool empty() { return positions.empty(); }
   /// Returns the number of constraints
   unsigned int size() const { return positions.size(); }
   
   // ACCESSORS FUNCTIONS
   /// Returns the initial positions of the i-th constraint
   ///@param i index of the constraint
   ///@return the deformed position
   const T &getConstraint(int i) const {
      return positions[i];
   }
   
   /// Sets the deformed positions of the i-th constraint with a new value
   ///@param i index of the constraint
   ///@param p the new position
   void setConstraint(int i, const T &c) {
      positions[i] = c;
   }
   
   vector<T>       positions;    //< positions of constraints
   vector<int>     ids;          //< id of the geometric object associated with the constraint 
};

#endif
